package max.ubitest.pipe.commands
{
	import max.ubitest.pipe.events.PipeEvent;
	import max.ubitest.pipe.locators.ComponentsLocator;
	import max.ubitest.pipe.view.ComponentRenderer;
	import max.ubitest.pipe.view.ToolBar;
	
	import mx.core.IVisualElementContainer;
	
	import org.robotlegs.mvcs.Command;
	
	public class MappedComponentSelectedCommand extends Command
	{
		[Inject]
		public var event:PipeEvent;
		[Inject]
		public var locator:ComponentsLocator;
		
		public function MappedComponentSelectedCommand()
		{
			super();
		}
		
		override public function execute():void{
			if(locator.edittingComponent){
				eventDispatcher.dispatchEvent(new PipeEvent(PipeEvent.RESET, null));
				locator.edittingComponent = null;
				return;
			}
			locator.edittingComponent = event.data as ComponentRenderer;
			var toolbar:ToolBar = new ToolBar();
			(contextView as IVisualElementContainer).addElement(toolbar);
		}
	}
}